<?php
namespace app\api\controller;
use app\common\controller\BaseApi;

/*进出记录api*/
class JpusHelper extends  BaseApi
{
	/**
	 * 测试地址
	 * http://tp5.com/api/JpusHelper/to_list/v/1/t/1/key/zwzl_admin/sign/5de093255ad3e78341dbe00309c9436c
	 * 
	 * $client = new \JPush\Client($app_key, $master_secret);
	 * */
	 public $client='';
	 public function _initialize()
    {
    	$this->client=new \JPush\Client("674e3e1415e04041246c6b11", "a1c8b1a0569946d5ffdc6576");
    }
	/**
	 * http://zwzl.com/api/JpusHelper/test/
	 * */
	public function test(){
		$this->send_notice();
	}
	//tv 盒子
	public function tv($alias,$type,$url=""){
		$push_payload = $this->client->push()
		    ->setPlatform(array('ios', 'android'))
			->addAlias($alias)		    
			->message('message content', array(
            'title' => 'tv盒子广告推送',
            'extras' => array(
                'type' => $type,
                'url'=>$url
            ),
        ));
			
		try {
		    $response = $push_payload->send();
			\Think\Log::write($response,"err");
		} catch (\JPush\Exceptions\APIConnectionException $e) {
			\Think\Log::write("推送出错APIConnectionException","err");
		} catch (\JPush\Exceptions\APIRequestException $e) {
			\Think\Log::write("推送出错APIRequestException","err");
		}
	}
	/**
	 * 发送设备更新信息
	 * */
	public  function send_notice($alias=array(''),$v="1.0",$url=""){
		$push_payload = $this->client->push()
		    ->setPlatform(array('ios', 'android'))
			->addAlias($alias)		    
			->message('message content', array(
            'title' => 'app更新推送',
            'extras' => array(
                'type' => '1',
                'url'=>$url,
                'version'=>$v
            ),
        ));
			
		try {
		    $response = $push_payload->send();
			\Think\Log::write($response,"err");
		} catch (\JPush\Exceptions\APIConnectionException $e) {
			\Think\Log::write("推送出错APIConnectionException","err");
		} catch (\JPush\Exceptions\APIRequestException $e) {
			\Think\Log::write("推送出错APIRequestException","err");
		}
	}	
////////////////////////////////////////////////////////////////////////////////////
}
